<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.0.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.14.0/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wanglong_kevin.gitee.io","root":"/","scheme":"Gemini","version":"8.0.0-rc.5","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false};
  </script>

  <meta name="description" content="发现 sshfs 更方便， 只需要在客户端配置即可将远程目录挂载到本地 12sudo apt install -y sshfssshfs user@host:&#x2F;remote_dir  local_dir 以下抛弃为解决本地机器同编译服务器代码同步问题，便想设置远程共享目录。编译服务器OS：centos7,本地机器OS：ubuntu18.04。 能想到的有samba、nfs, nfs mo">
<meta property="og:type" content="article">
<meta property="og:title" content="linux 下共享远程文件夹">
<meta property="og:url" content="https://wanglong_kevin.gitee.io/2019/07/23/linux-nfs/index.html">
<meta property="og:site_name" content="冬天里的小木屋">
<meta property="og:description" content="发现 sshfs 更方便， 只需要在客户端配置即可将远程目录挂载到本地 12sudo apt install -y sshfssshfs user@host:&#x2F;remote_dir  local_dir 以下抛弃为解决本地机器同编译服务器代码同步问题，便想设置远程共享目录。编译服务器OS：centos7,本地机器OS：ubuntu18.04。 能想到的有samba、nfs, nfs mo">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-07-23T06:50:24.000Z">
<meta property="article:modified_time" content="2019-07-24T16:00:00.000Z">
<meta property="article:author" content="Kevin">
<meta property="article:tag" content="linux nfs">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://wanglong_kevin.gitee.io/2019/07/23/linux-nfs/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>linux 下共享远程文件夹 | 冬天里的小木屋</title>
  






  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">冬天里的小木屋</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">The Winter Room</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <section class="post-toc-wrap sidebar-panel">
          <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E9%85%8D%E7%BD%AE"><span class="nav-number">1.</span> <span class="nav-text">服务端配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%85%8D%E7%BD%AE"><span class="nav-number">2.</span> <span class="nav-text">客户端配置</span></a></li></ol></div>
      </section>
      <!--/noindex-->

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Kevin"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Kevin</p>
  <div class="site-description" itemprop="description">NOT a coder, but an artist.</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">8</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </section>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">
      

      

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wanglong_kevin.gitee.io/2019/07/23/linux-nfs/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Kevin">
      <meta itemprop="description" content="NOT a coder, but an artist.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="冬天里的小木屋">
    </span>

    
    
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          linux 下共享远程文件夹
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-07-23 14:50:24" itemprop="dateCreated datePublished" datetime="2019-07-23T14:50:24+08:00">2019-07-23</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-07-25 00:00:00" itemprop="dateModified" datetime="2019-07-25T00:00:00+08:00">2019-07-25</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <p><strong>发现 sshfs 更方便， 只需要在客户端配置即可</strong><br>将远程目录挂载到本地</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo apt install -y sshfs</span><br><span class="line">sshfs user@host:&#x2F;remote_dir  local_dir</span><br></pre></td></tr></table></figure>
<p><strong>以下抛弃</strong><br><del>为解决本地机器同编译服务器代码同步问题，便想设置远程共享目录。<br>编译服务器OS：centos7,本地机器OS：ubuntu18.04。 能想到的有samba、nfs, nfs mount 方式
相对来说更符合习惯一点。</del>    </p>
<a id="more"></a>
<h2 id="服务端配置"><a href="#服务端配置" class="headerlink" title="服务端配置"></a>服务端配置</h2><ul>
<li>安装nfs<br><code>sudo yum install rpcbind nfs-utils</code></li>
<li>配置nfs<br><code>sudo echo /home/kevin/com 10.21.140.63(rw,sync,no_root_squash) &gt; /etc/exports</code>  <blockquote>
<p>格式为&lt;共享目录路径&gt; 客户端（访问权限，用户映射，其他）  </p>
<blockquote>
<p>  客户端常用的指定方式</p>
<blockquote>
<p>    指定ip地址的主机：192.168.100.1<br>    指定一个子网：192.168.100.0/24 也可以写成:192.168.100.0/255.255.255.0<br>    指定域名的主机：david.bsmart.cn<br>    指定域中的所有主机：*.bsmart.cn<br>    所有主机：*  </p>
</blockquote>
</blockquote>
</blockquote>
</li>
</ul>
<blockquote>
<blockquote>
<p>选项用来设置输出目录的访问权限、用户映射等。<br>NFS主要有3类选项：</p>
<blockquote>
<p>    设置输出目录只读：ro<br>    设置输出目录读写：rw  </p>
</blockquote>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<p>用户映射选项  </p>
<blockquote>
<p>    all_squash：将远程访问的所有普通用户及所属组都映射为匿名用户或用户组（nfsnobody）；<br>    no_all_squash：与all_squash取反（默认设置）；<br>    root_squash：将root用户及所属组都映射为匿名用户或用户组（默认设置）；<br>    no_root_squash：与rootsquash取反；<br>    anonuid=xxx：将远程访问的所有用户都映射为匿名用户，并指定该用户为本地用户（UID=xxx）；<br>    anongid=xxx：将远程访问的所有用户组都映射为匿名用户组账户，并指定该匿名用户组账户为本地用户组账户（GID=xxx）；  </p>
</blockquote>
</blockquote>
</blockquote>
<blockquote>
<blockquote>
<p>其它选项</p>
<blockquote>
<p>    secure：限制客户端只能从小于1024的tcp/ip端口连接nfs服务器（默认设置）；<br>    insecure：允许客户端从大于1024的tcp/ip端口连接服务器；<br>    sync：将数据同步写入内存缓冲区与磁盘中，效率低，但可以保证数据的一致性；<br>    async：将数据先保存在内存缓冲区中，必要时才写入磁盘；<br>    wdelay：检查是否有相关的写操作，如果有则将这些写操作一起执行，这样可以提高效率（默认设置）； 
    no_wdelay：若有写操作则立即执行，应与sync配合使用；<br>    subtree：若目录是一个子目录，则nfs服务器将检查其父目录的权限(默认设置)；<br>    no_subtree：即使输出目录是一个子目录，nfs服务器也不检查其父目录的权限，这样可以提高效率； </p>
</blockquote>
</blockquote>
</blockquote>
<ul>
<li>启动服务<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">service enable nfs</span><br><span class="line">service enable rpcbind</span><br><span class="line">service start nfs</span><br><span class="line">service start rpcbind</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="客户端配置"><a href="#客户端配置" class="headerlink" title="客户端配置"></a>客户端配置</h2><ul>
<li>安装nfs<br><code>sudo apt install nfs-common</code></li>
<li>查看远程目录<br><code>showmount  10.21.145.213 -e</code> </li>
<li>挂载目录<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir com   </span><br><span class="line">mount  -t nfs com:&#x2F;home&#x2F;kevin&#x2F;com com</span><br></pre></td></tr></table></figure>

</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/linux-nfs/" rel="tag"># linux nfs</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2019/01/03/patch-syntax/" rel="prev" title="quilt patch 语法记录">
                  <i class="fa fa-chevron-left"></i> quilt patch 语法记录
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2019/09/26/bpf/" rel="next" title="BPF & XDP 知识分享">
                  BPF & XDP 知识分享 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
      </footer>
    
  </article>
  
  
  



      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kevin</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

      








    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.0/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  















  

  

</body>
</html>
